package com.lagou.dao;

import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: lcz
 * @date: Created in 13:05 2021/2/24
 * @description:
 */
@Component
public class PayDAO {
    private static Map<String, String> map = new ConcurrentHashMap<>();

    private static List<String> timeoutBizList = Collections.synchronizedList(new ArrayList<>());


    public Boolean exists(String bizId) {
        return map.get(bizId) != null;
    }

    public void set(String bizId, String value) {
        map.put(bizId, value);
    }

    public void setBizByTimeout(String bizId) {
        timeoutBizList.add(bizId);
    }

    public Boolean validBiz(String bizId) {
        return !timeoutBizList.contains(bizId);
    }

    public List<String> list() {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        List<String> list = new ArrayList<>();
        while (iterator.hasNext()) {
            Map.Entry<String, String> next = iterator.next();
            String s = next.getKey() + "---" + next.getValue();
            list.add(s);
        }
        return list;
    }

    public List<String> listTimeoutBiz() {
        return timeoutBizList;
    }
}
